<?php
if( !defined('DS') ) define( 'DS' , DIRECTORY_SEPARATOR );
function load($filename){
    return include AROOT.DS.'lib'.DS.$filename;
}
function transcribe($aList, $aIsTopLevel = true)
{
    $gpcList = array();
    $isMagic = get_magic_quotes_gpc();

    foreach ($aList as $key => $value) {
        if (is_array($value)) {
            $decodedKey = ($isMagic && !$aIsTopLevel)?stripslashes($key):$key;
            $decodedValue = transcribe($value, false);
        } else {
            $decodedKey = stripslashes($key);
            $decodedValue = ($isMagic)?stripslashes($value):$value;
        }
        $gpcList[$decodedKey] = $decodedValue;
    }
    return $gpcList;
}

$_GET = transcribe( $_GET );
$_POST = transcribe( $_POST );
$_REQUEST = transcribe( $_REQUEST );

function v( $str )
{
    return isset( $_REQUEST[$str] ) ? $_REQUEST[$str] : false;
}

function z( $str )
{
    return strip_tags( $str );
}

function c( $str )
{
    return isset( $GLOBALS['config'][$str] ) ? $GLOBALS['config'][$str] : false;
}

function g( $str )
{
    return isset( $GLOBALS[$str] ) ? $GLOBALS[$str] : false;
}

function t( $str )
{
    return trim($str);
}

function u( $str )
{
    return urlencode( $str );
}

function r($url){
    header("Location:$url");
}

// render functiones
function render( $data = NULL , $sharp = 'default' )
{
    $GLOBALS['sharp'] = $sharp;

    $layout_file = AROOT . 'view/'. $sharp . '.tpl.php';
    if( file_exists( $layout_file ) )
    {
        @extract( $data );
        require( $layout_file );
    }
}

function ajax_echo( $info )
{
    if( !headers_sent() )
    {
        header("Content-Type:text/html;charset=utf-8");
        header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
        header("Cache-Control: no-cache, must-revalidate");
        header("Pragma: no-cache");
    }
    echo $info;
}

function show_msg($msg,$url=''){
    $data['msg'] = $msg;
    $data['url'] = $url;
    render($data,'msg');
}

